package com.woniu.owner.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.common.ResponseData;
import com.woniu.owner.entity.MaintenanceInfo;
import com.woniu.owner.service.MaintenanceInfoService;
import com.woniu.owner.mapper.MaintenanceInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author admin
 * @description 针对表【maintenance_info】的数据库操作Service实现
 * @createDate 2025-01-10 10:31:29
 */
@Service
public class MaintenanceInfoServiceImpl extends ServiceImpl<MaintenanceInfoMapper, MaintenanceInfo>
        implements MaintenanceInfoService {
    @Autowired
    private MaintenanceInfoMapper maintenanceInfoMapper;

    @Override
    public ResponseData<?> addMaintenanceInfo(MaintenanceInfo maintenanceInfo) {
        save(maintenanceInfo);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryMaintenanceInfo(String phone) {
        List<MaintenanceInfo> maintenanceInfos = lambdaQuery().eq(MaintenanceInfo::getPhone,phone).list();
        return new ResponseData<>().ok(maintenanceInfos);
    }

    @Override
    public ResponseData<?> updateMaintenanceInfo(MaintenanceInfo maintenanceInfo) {
        lambdaUpdate().eq(MaintenanceInfo::getId, maintenanceInfo.getId())
                .set(MaintenanceInfo::getAddress, maintenanceInfo.getAddress())
                .set(MaintenanceInfo::getAppointmentDate, maintenanceInfo.getAppointmentDate())
                .set(MaintenanceInfo::getDescription, maintenanceInfo.getDescription())
                .set(MaintenanceInfo::getImages, maintenanceInfo.getImages())
                .set(MaintenanceInfo::getPhone, maintenanceInfo.getPhone())
                .set(MaintenanceInfo::getRepairId, maintenanceInfo.getRepairId())
                .set(MaintenanceInfo::getTitle, maintenanceInfo.getTitle())
                .update();
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> deleteMaintenanceInfo(Integer id) {
        maintenanceInfoMapper.deleteById(id);
        return new ResponseData<>().ok();
    }
}




